//
//  EditPassWordViewController.m
//  DirectProDuct
//
//  Created by hl on 16/1/22.
//  Copyright (c) 2016年 ping. All rights reserved.
//

#import "EditPassWordViewController.h"

@interface EditPassWordViewController ()<UITextFieldDelegate>{
    UIScrollView *backScrollView;
    UITextField *linShiFeld;
}

@end

@implementation EditPassWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    
    [self drawNavWithTitle:@"基本信息"];
    [self drawBackButton];
    [self drawView];
    // Do any additional setup after loading the view.
}
-(void)keyboardWillShow:(id)aNotification{
    //获取键盘的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    backScrollView.frame = CGRectMake(0, 78, KScreenWidth, KScreenHeight - 78 - keyboardRect.size.height);
    
}
-(void)keyboardWillHide:(id)sender{
    backScrollView.frame = CGRectMake(0, 78, KScreenWidth, KScreenHeight - 78);
}

-(void)drawView{
    backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 78, KScreenWidth, KScreenHeight - 78)];
    backScrollView.scrollEnabled = YES;
    backScrollView.contentSize = CGSizeMake(0, KScreenHeight -78);
    [self.view addSubview:backScrollView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenKeyBoard)];
    [backScrollView addGestureRecognizer:tap];
    
    NSArray *tipArr = @[@"*原始密码",@"*新的密码",@"*确认密码"];
    
    for (int i = 0; i<tipArr.count; i++) {
        UILabel *tipLab = [[UILabel alloc] initWithFrame:CGRectMake(15 * _kscW, 25 * _kscH + 50 * _kscH * i, 60 * _kscW, 30 *_kscH)];
        tipLab.attributedText = [self returnAttributedStringWithString:[tipArr objectAtIndex:i]];
        [backScrollView addSubview:tipLab];
        
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(tipLab.right, tipLab.top, KScreenWidth - tipLab.right - 15 * _kscW, tipLab.height)];
        textField.tag = i;
        textField.returnKeyType = UIReturnKeyDone;
        textField.layer.cornerRadius = 4;
        textField.clipsToBounds = YES;
        textField.delegate = self;
        textField.layer.borderWidth = 1 * _kscH;
        textField.layer.borderColor = XiaHuaXianCOLOR.CGColor;
        [backScrollView addSubview:textField];
        
    }
    
    UIButton *queDingBtn = [[UIButton alloc] initWithFrame:CGRectMake((KScreenWidth-60 * _kscW)/2, 25 * _kscH + 50 * _kscH * 3+ 30 * _kscH, 60 * _kscW, 35 * _kscH)];
    queDingBtn.layer.cornerRadius = 3;
    queDingBtn.clipsToBounds = YES;
    [queDingBtn setBackgroundColor:[UIColor redColor]];
    [queDingBtn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [queDingBtn setTitle:@"确定" forState:UIControlStateNormal];
    queDingBtn.titleLabel.font = [UIFont fontWithName:TextJiaCu size:14.0];
    [backScrollView addSubview:queDingBtn];
}
-(NSAttributedString *)returnAttributedStringWithString:(NSString *)str{
    NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc]initWithString:str];
    
    [attriStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 1)];
    [attriStr addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(1, str.length -1)];
    [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13.0f] range:NSMakeRange(0, str.length)];
    
    return attriStr;
    
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    linShiFeld = textField;
    return YES;
}
#pragma mark 确定按钮点击方法
-(void)buttonClicked:(UIButton *)btn{
    
}
-(void)hiddenKeyBoard{
    [linShiFeld resignFirstResponder];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
